import React, { Component } from 'react';
import { Text, Image, View, TextInput, TouchableOpacity, ScrollView } from 'react-native';
import { unitWidth } from '../constants/AdapterUtil';
import { MyHeader } from '../components/MyHeader';
import Colors from '../constants/Colors';
import { postFetch } from '../constants/HttpExtension';
import { show } from '../constants/Toast';
import { api_member_info_Certification } from '../constants/HttpServices';
import { SubmitButton1 } from '../components/Button';
import { MyInput1 } from '../components/Input';
import TextUtil from '../constants/TextUtil';
import { ExamineView } from '../components/EmptyView';

export default class EnterpriseCertificationScreen extends Component {

    constructor(props) {
        super(props)

        const { navigation } = this.props;
        this.state = {
            corporation_name: '',
            IDCard: '',
            regid: '',
            accounttotal: '',

            showExamineView: global.companyInfo && global.companyInfo.certification_info ? true : false
        }
    }

    componentWillMount() {

    }

    componentWillUnmount() {

    };

    render() {
        if (this.state.showExamineView) {
            let view;
            if (global.companyInfo.certification_info.is_pass == '0') {
                view = <ExamineView showRecertification={false} onPress={() => { }} reason='正在审核' />
            } else if (global.companyInfo.certification_info.is_pass == '1') {
                view = <ExamineView showRecertification={false} onPress={() => { }} reason='审核通过' />
            } else if (global.companyInfo.certification_info.is_pass == '2') {
                view = <ExamineView showRecertification={true} onPress={() => { this.setState({ showExamineView: false }) }} reason={'审核不通过原因：' + global.companyInfo.certification_info.remark} />
            }
            return (
                <View style={{ flex: 1, backgroundColor: Colors.colorEF }}>
                    <MyHeader title='企业认证' leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} />
                    {view}
                </View>
            );
        }
        return (
            <View style={{ flex: 1, backgroundColor: Colors.colorEF }}>
                <MyHeader title='企业认证' leftImg={require('../res/ic_arrow_left.png')} leftClick={() => { this.props.navigation.pop() }} />
                <ScrollView style={{ flex: 1 }} showsVerticalScrollIndicator={false}>
                    <View>
                        <MyInput1
                            style={{ marginTop: 0 * unitWidth }}
                            onChangeText={this.onCorporationNameTextChange.bind(this)}
                            title={
                                <Text style={{ color: Colors.black, fontSize: 15 }}>法人姓名：</Text>
                            }
                            maxLength={20}
                            placeholder='请输入法人姓名'
                            value={this.state.corporation_name} isLast={false} />
                        <MyInput1
                            style={{ marginTop: 0 * unitWidth }}
                            onChangeText={this.onIDCardTextChange.bind(this)}
                            title={
                                <Text style={{ color: Colors.black, fontSize: 15 }}>法人身份证号：</Text>
                            }
                            maxLength={20}
                            placeholder='请输入法人身份证号'
                            value={this.state.IDCard} isLast={false} filterType={3} />
                        <MyInput1
                            style={{ marginTop: 0 * unitWidth }}
                            onChangeText={this.onRegidTextChange.bind(this)}
                            title={
                                <Text style={{ color: Colors.black, fontSize: 15 }}>工商注册号：</Text>
                            }
                            maxLength={50}
                            placeholder='请输入工商注册号'
                            value={this.state.regid} isLast={false} />
                        <MyInput1
                            style={{ marginTop: 0 * unitWidth }}
                            onChangeText={this.onAccounttotalTextChange.bind(this)}
                            title={
                                <Text style={{ color: Colors.black, fontSize: 15 }}>公司人数：</Text>
                            }
                            maxLength={20}
                            keyboardType='numeric'
                            placeholder='请输入公司人数'
                            value={this.state.accounttotal} isLast={true} />
                        <SubmitButton1 style={{ marginTop: 200 * unitWidth, alignSelf: 'center' }} text='提交认证' onPress={() => {
                            this.submit();
                        }} />
                    </View>
                </ScrollView>
            </View>
        );
    }

    onCorporationNameTextChange(text) {
        this.setState({
            corporation_name: text
        })
    }

    onIDCardTextChange(text) {
        this.setState({
            IDCard: text,
        })
    }

    onRegidTextChange(text) {
        this.setState({
            regid: text
        })
    }

    onAccounttotalTextChange(text) {
        this.setState({
            accounttotal: text,
        })
    }

    submit() {
        if (this.state.corporation_name == '') {
            show('请输入法人姓名');
            return;
        } else if (this.state.IDCard == '') {
            show('请输入法人身份证号');
            return;
        } else if (this.state.regid == '') {
            show('请输入工商注册号');
            return;
        } else if (this.state.accounttotal == '') {
            show('请输入公司人数');
            return;
        }
        let params = {
            'corporation_name': this.state.corporation_name,
            'IDCard': this.state.IDCard,
            'regid': this.state.regid,
            'accounttotal': this.state.accounttotal,
        }
        postFetch(api_member_info_Certification, params, {
            success: (response) => {
                show('上传成功');
                this.props.navigation.pop();
            },
            fail: (response) => {
                show(response.result.message);
            }
        })
    }
}